package com.marktotop.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.marktotop.entity.Salary;
import com.marktotop.response.ResultBean;
import com.marktotop.response.ResultCode;
import com.marktotop.service.ISalaryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author marktotop
 * @since 2021-05-23
 */
@RestController
@RequestMapping("/salary/basic")
@Api(tags = "工资套账接口")
public class SalaryController {

    @Autowired
    private ISalaryService salaryService;
    /**
     * 分页显示所有工资账套信息+条件查询
     * @return
     */
    @RequestMapping(value = "/",method = RequestMethod.GET )
    @ApiOperation(value = "获取所有套账信息")
    public ResultBean findAllByPage(@RequestParam(defaultValue = "1") Integer currentPage,
                                    @RequestParam(defaultValue = "10") Integer size, Salary salary) {
      return salaryService.findAllByPage(currentPage,size,salary);
    }
    /**
     * 删除套账信息
     */
    @RequestMapping(value = "/{id}",method = RequestMethod.DELETE )
    @ApiOperation(value = "删除套账信息",notes = "DELETE方式删除员工信息")
    public ResultBean deleteSalary(@PathVariable Integer id) {
        if (salaryService.removeById(id)){
            return ResultBean.ok().message("删除套账成功！");
        }
        return ResultBean.error().message("删除套账失败！");
    }
    /**
     * 新增套账信息
     */
    @RequestMapping(value = "/",method = RequestMethod.POST)
    @ApiOperation(value = "新增套账信息",notes = "以post方式提交套账信息")
    public ResultBean addSalary(@RequestBody Salary salary){
       return  salaryService.addSalary(salary);
    }
    /**
     * 更新套账信息
     */
    @RequestMapping(value = "/",method = RequestMethod.PUT )
    @ApiOperation(value = "更新套账信息",notes = "put方式更新信息")
    public ResultBean updateSalary(@RequestBody Salary salary) {
        if (salaryService.updateById(salary)){
            return ResultBean.ok().message("更新套账成功！");
        }
        return ResultBean.error().message("更新套账失败！");
    }
}
